package com.example.provider2.listener;


import com.alibaba.fastjson.JSONObject;
import com.example.entity.UserTest;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.stereotype.Component;

/**
 * @author tianzhuang
 * @version 1.0
 * @date 2021/11/7 23:59
 */
@Component
public class Provider2Listener {
    /**
     * work模式
     * @param msg
     */
/*    @RabbitListener(queues = "testqueue")
    private void listener2(String msg) {
        UserTest userTest = JSONObject.parseObject(msg, UserTest.class);
        System.err.println("this is listener2" + userTest);
    }*/
    @RabbitListener(queues = "testqueue")
    private void listener2(Message msg) {
        String s = new String(msg.getBody());
        UserTest userTest = JSONObject.parseObject(s, UserTest.class);
        System.err.println("this is listener 2 接收到的消息为：" + userTest);
    }

/*
    @RabbitListener(queues = "testqueue")
    private void listener2(byte[] bs) {
        UserTest test = (UserTest) SerializationUtils.deserialize(bs);
        System.err.println("this is listener2" + test.toString());
    }*/


    @RabbitListener(queues = "testqueuqe1")
    private void testqueue1Listener2(Message msg) {
        String s = new String(msg.getBody());
        UserTest userTest = JSONObject.parseObject(s, UserTest.class);
        System.err.println("this is listener2" + userTest);
    }


    @RabbitListener(queues = "testqueuqe4")
    private void testqueue1Listener2ByKey(Message msg) {
        String s = new String(msg.getBody());
        UserTest userTest = JSONObject.parseObject(s, UserTest.class);
        System.err.println("this is listener2" + userTest);
    }


    @RabbitListener(queues = "testqueuqe6")
    private void testqueue1Listener2ByTopic(Message msg) {
        String s = new String(msg.getBody());
        UserTest userTest = JSONObject.parseObject(s, UserTest.class);
        System.err.println("this is listener2" + userTest);
    }


}
